package com.ldq.imooc.basics.io;

import java.io.Serializable;

/**
 * @Author : 李道泉
 * @Description :
 * @Date : 2018/4/17 15:42
 * @Modified by :
 */
public class Student implements Serializable {

    private String id;

    private transient int age;

    private String name;

    @Override
    public String toString() {
        return "Student{" +
                "id='" + id + '\'' +
                ", age=" + age +
                ", name='" + name + '\'' +
                '}';
    }

    public Student() {
    }

    public Student(String id, int age, String name) {
        this.id = id;
        this.age = age;
        this.name = name;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException {

        //把jvm能默认序列化的元素进行序列化操作
        s.defaultWriteObject();
        //自己完成age的序列化
        s.writeInt(age);
    }

    private void readObject(java.io.ObjectInputStream s) throws java.io.IOException, ClassNotFoundException {

        //把jvm能默认反序列化的元素进行反序列化操作
        s.defaultReadObject();
        //自己完成age反序列化操作
        this.age = s.readInt();
    }
}
